<template>
  <view class="page">
    <view class="container" @click="setUserInfo">
      <view class="blue-line">
        <text>头像</text>
      </view>
      <view class="red-line">
        <image class="logo" :src="userInfo.avatar" />
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view>
    <view class="container" @click="setUserInfo">
      <view class="blue-line">
        <text>昵称</text>
      </view>
      <view class="red-line">
        <text>{{ userInfo.nickName }}</text>
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view>
	
	<view class="container" @click="setSuperior">
	  <view class="blue-line">
	    <text>我的推荐人</text>
	  </view>
	  <view class="red-line">
	    <image class="drop" src="/static/images/drop.png"></image>
	  </view>
	</view>
	
    <view class="container" @click="setAddress">
      <view class="blue-line">
        <text>地址管理</text>
      </view>
      <view class="red-line">
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view>
<!--    <view class="container" @click="setPassword">
      <view class="blue-line">
        <text>余额支付密码</text>
      </view>
      <view class="red-line">
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view> -->
    <view class="container" @click="toPrivacy">
      <view class="blue-line">
        <text>隐私协议</text>
      </view>
      <view class="red-line">
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view>
    <!-- <view class="container" @click="accountWriteoff">
      <view class="blue-line">
        <text>账号注销</text>
      </view>
      <view class="red-line">
        <image class="drop" src="/static/images/drop.png"></image>
      </view>
    </view> -->
    <view class="bottom">
      <button type="default" class="black" @click="logout" :plain="true">
        退出登录
      </button>
    </view>
  </view>
</template>

<script>
import loginApi from "@/api/login";
import userApi from "@/api/user";
import { removeToken } from "@/utils/auth";

export default {
  name: "setup",
  components: {},
  data() {
    return {
      rateValue: 5,
      value: "",
      userInfo: {},
    };
  },
  onLoad(options) {},
  onShow() {
    this.getUserInfo();
  },
  methods: {
    getUserInfo() {
      let userInfo = uni.getStorageSync("userInfo");
      userApi.fetchUserInfo().then((res) => {
        if (res.code == 200) {
          this.userInfo = res.user;
          uni.setStorageSync("userInfo", {
            ...userInfo,
            nickName: res.user.nickName,
            avatar: res.user.avatar,
            memberLevel: res.memberUserInfo.memberLevel,
            agencyLevel: res.memberUserInfo.memberAgencyLevel,
            phone: res.user.phonenumber,
            payPassword: res.user.payPassword, // 是否设置过支付密码
            parentNickName: res.bdmUser.parentNickName, // 绑定的上级用户名
          });
        }
      });
    },
    pageTo(url) {
      uni.navigateTo({
        url: url,
      });
    },
    setUserInfo() {
      uni.navigateTo({
        url: `/subPages/mine/userInfo?avatar=${this.userInfo.avatar}&nickName=${this.userInfo.nickName}`,
      });
    },
	setSuperior() {
      uni.navigateTo({
        url: "/subPages/mine/superior",
      });
    },
    setAddress() {
      uni.navigateTo({
        url: "/subPages/mine/myAddress",
      });
    },
    setPassword() {
      uni.navigateTo({
        url: "/subPages/mine/administrator",
      });
    },
    toPrivacy() {
		uni.navigateTo({
			url:`/pages/agreement?type=2`
		})
      // uni.navigateTo({
      //   url: "/subPages/mine/agreements",
      // });
    },
    logout() {
      loginApi.logout().then((res) => {
        if (res.code == 200) {
          removeToken();
          uni.removeStorageSync("sessionKey");
          uni.removeStorageSync("userInfo");
          uni.removeStorageSync("cartProduct");
          uni.removeStorageSync("selectedAddress");
          uni.showToast({
            title: "退出成功",
            icon: "none",
          });
          setTimeout(() => {
            uni.switchTab({
              url: "/pages/index2",
            });
          }, 1500);
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.page {
  background: #fff;
  width: 100vw;
  height: 100vh;
  padding: 20rpx 38rpx;
}

.container {
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 122rpx;
  border-bottom: 1px solid #ebebeb;

  .drop {
    width: 42rpx;
    height: 42rpx;
    margin-left: 14rpx;
  }

  .red-line {
    display: flex;
    align-items: center;
  }

  .blue-line {
    color: #000000;
    font-family: "PingFang SC";
    font-size: 30rpx;
    font-style: normal;
    font-weight: 500;
    line-height: normal;
    opacity: 0.9;
  }

  .logo {
    width: 68rpx;
    height: 68rpx;
    border-radius: 50%;
  }

  .red-line {
    color: #000000;
    text-align: right;
    font-family: "PingFang SC";
    font-size: 30rpx;
    font-style: normal;
    font-weight: 400;
    line-height: normal;
  }
}

.bottom {
  border-top: 1px solid #dddddd;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 150rpx;
  position: absolute;
  bottom: 0;
  left: 0;

  .black {
    background-color: #000;
    color: #fff;
    border-radius: 25px;
    width: 80%;
  }
}
</style>
